﻿Imports System.Net
Imports System.IO

Partial Class DetailKhachSanImage
    Inherits System.Web.UI.Page
    Public op_load As String = "style=""display:none;"""
    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        If Session("IDCity") Is Nothing Or Request.QueryString("IDKS") Is Nothing Then
            Response.Redirect("~/index.aspx")
        End If
        If Not IsPostBack Then
            'DetailKhachSan.aspx?IDKS={0}
            Dim khachSan As KhachSan = Nothing
            If Request.QueryString("IDKS") IsNot Nothing Then
                Dim idKS As New Guid(Request.QueryString("IDKS"))
                khachSan = KhachSanServer.GetKhachSanByIDKhachSan(idKS)
                ' Dim strCity As String = KhachSanServer.GetCityNameByIDCity(khachSan.CITY_ID)

                'Dim arrivalDate As Date = Session("ArrivalDate")
                'Dim departureDate As Date = Session("DepartureDate")
                'Dim nDays As Long = DateDiff("d", arrivalDate, departureDate)
                'Dim _Date As Date = DateAdd(DateInterval.Day, +1, Now.Date)
                'Dim strDayWeek As String = String.Format("{0} {1}", Util.GetStrThuTrongTuan(arrivalDate.DayOfWeek), Format("MM/dd/yyyy", arrivalDate))
                'Dim lstItem As New ListItem(nDays, arrivalDate)

                divNameHotel.InnerHtml = khachSan.NAME
                lnkQuayLai.Text = "Khách Sạn tại " + Session("NameCity")
                Dim strURLQuayLai As String = String.Format("~/SearchKhachSan.aspx?ArrivalDate={0}&DepartureDate={1}&CityID={2}&Guests={3}&Rooms={4}", Session("ArrivalDate"), Session("DepartureDate"), Session("IDCity"), Session("Guests"), Session("Rooms"))
                lnkQuayLai.PostBackUrl = strURLQuayLai

                Dim ks As KhachSan = KhachSanServer.GetKhachSanByIDKhachSan(idKS)
                divVideo.InnerHtml = ""
                divImage.InnerHtml = ""
                Dim arrVideo() As String = Split(ks.VIDEO_LIST, "[SPACE]")
                Dim arrImages() As String = Split(ks.IMG_LIST, "[SPACE]")
                For i As Integer = 0 To arrVideo.Length - 1
                    If Not arrVideo(i).Equals("") Then
                        divVideo.InnerHtml = divVideo.InnerHtml + arrVideo(i)
                    End If
                Next
                If arrImages.Length > 9 Then
                    op_load = String.Format("onclick=""LoadContinuesListImageAndVideo(this)"" p=""10"" c=""{0}""", arrImages.Length - 1)
                End If
                For j As Integer = 0 To arrImages.Length - 1
                    If Not arrImages(j).Equals("") Then
                        Dim style_img As String = ""
                        If j > 9 Then
                            style_img = "style=""display:none;"""
                        End If
                        Dim urlImage As String = GetLinkImage(arrImages(j))
                        divImage.InnerHtml = divImage.InnerHtml + String.Format("<div id=""img_d_{2}""  {1}><img  data-original='{0}' class='lazy pt-item' src='{0}' /></div>", urlImage, style_img, j)
                    End If
                Next
                Dim listLoaiPhong As List(Of KhachSan) = KhachSanServer.GetLoaiHotelByIdHotel(idKS)
                lnkDatPhong.PostBackUrl = String.Format("~/DetailKhachSanPut.aspx?IDKS={0}&IDLP={1}", Request.QueryString("IDKS"), listLoaiPhong(0).IDLOAIPHONG)

            End If
          
        End If
    End Sub

    Private Function GetLinkImage(ByVal urlImg As String) As String
        Dim strURL As String = ""
        Dim webRequest As WebRequest
        Dim webResponse As WebResponse
        Try
            If urlImg.ToUpper.IndexOf("HTTP://") > -1 Or urlImg.ToUpper.IndexOf("HTTPS://") > -1 Then
                webRequest = webRequest.Create(urlImg)
                webResponse = webRequest.GetResponse()
                strURL = urlImg
            Else
                strURL = String.Format("http://www.khachsan24gio.vn{0}", urlImg)
            End If
        Catch ex As Exception
            Return False
        End Try
        Return strURL
    End Function

End Class
